<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OSSJK 2.0</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
<style>
.detailTable_text {
	font-weight: bold;
}
</style>
</head>
<body class="childrenBody">
	<form class="layui-form" lay-filter="formTest" id="form">
		<table class="layui-table mag0">
			<colgroup>
				<col width="15%">
				<col width="30%">
				<col width="15%">
				<col width="30%">
			</colgroup>
			<tbody class="detailTable">
				<tr>
					<td class="detailTable_text">学校名</td>
					<td colspan="3"><input type="text" class="layui-input " lay-verify="required" placeholder="请输入真实姓名" name="name"></td>
				</tr>
				<tr>
					<td class="detailTable_text">跟进人</td>
					<td><select name="eid" id="eid" class="searchVal" lay-verify="required">
							<option value="">请选择</option>
					</select></td>
					<td class="detailTable_text">合作级别</td>
					<td><select name="level" id="level" lay-verify="required">
							<option value="">请选择</option>
							<option value="1">深度合作</option>
							<option value="2">一般合作</option>
							<option value="3">意向合作</option>
							<option value="4">没合作</option>
					</select></td>
				</tr>
				<tr>
					<td class="detailTable_text">省市级</td>
					<td colspan="3"><div class="layui-form-item">
							<div id="area"></div>
						</div></td>
				</tr>
				<tr>
					<td class="detailTable_text">详细地址</td>
					<td colspan="3"><input type="text" name="addr" id="addr" lay-verify="required" autocomplete="off" class="layui-input"></td>
				</tr>
				<tr>
					<td class="detailTable_text">备注</td>
					<td colspan="3"><input type="text" class="layui-input" placeholder="" name="remarks"></input></td>
				</tr>
			</tbody>
		</table>
		<div class="magt10 layui-right">
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="submit">提交</button>
				<button type="button" class="layui-btn layui-btn-sm layui-btn-primary close-btn">取消</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/js/index.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/constant.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript">
		layui.config({
			base : '../../../static/plugin/layui_extends/'
		}).extend({
			selectN : 'selectN'
		}).use([ 'selectN', 'form', 'table', 'laydate', 'layer' ], function() {
			var form = layui.form;
			var table = layui.table;
			var laydate = layui.laydate;
			var selectN = layui.selectN;
			var layer = parent.layer === undefined ? layui.layer : top.layer, $ = layui.jquery;
			var insertApi = "../../../advisory/school/insert";
			var toUpdateApi = "../../../advisory/school/toUpdate";
			var updateApi = "../../../advisory/school/update";
			var getEmployeeApi = "../../../getEmployee";
			var getAreaApi = "../../../getArea";
			var insertMethod = "post";
			var updateMethod = "put";
			var url = insertApi;
			var method = insertMethod;
			var areaData;
			var areaDefaults = [];

			var id = getUrlParam("id");
			loadAjax( getEmployeeApi, "get", null, function(response) {
				baseCallBack(response, function(response) {
					if (response.data && response.data.length) {
						for(var  v  of  response.data ){
							$("#eid").append('<option value="'+v.id+'">'+v.rname+'</option>');
							form.render("select"); 
						}
					}
					if (id) {
						//更新
						$("#form").append("<input type='hidden' name='id' value='' >");
						method = updateMethod;
						url = updateApi;
						loadAjax( toUpdateApi + "/" + id, "get", null, function(response) {
							baseCallBack(response, function(response) {
								fomrVal(form, "formTest", response.data.school);
								$("#eid").val(response.data.employee.id);
								//省市区联动
								loadAjax( getAreaApi, "get", null, function(response2) {
									baseCallBack(response2, function(response2) {
										areaData = response2.data;
										//无限级分类-所有配置
										selectN({
											//元素容器【必填】
											elem : '#area',
											data : areaData, //候选数据【必填】
											width : null,//设置了长度
											last : false, //为真只取最后一个值
											selected : response.data.areaIds,//默认值
											tips : '请选择', //空值项提示，可设置为数组['请选择省','请选择市','请选择县']
											name : 'areaIds',//input的name 不设置与选择器相同(去#.)
											delimiter : ',',//数据分隔符
											field : {//数据的键名
												idName : 'id',
												titleName : 'name',
												childName : 'children'
											}
										});
									});
								});
							});
						});
					}else{
						//省市区联动
						loadAjax( getAreaApi, "get", null, function(response2) {
							baseCallBack(response2, function(response2) {
								areaData = response2.data;
								//无限级分类-所有配置
								selectN({
									//元素容器【必填】
									elem : '#area',
									data : areaData, //候选数据【必填】
									width : null,//设置了长度
									last : false, //为真只取最后一个值
									tips : '请选择', //空值项提示，可设置为数组['请选择省','请选择市','请选择县']
									name : 'areaIds',//input的name 不设置与选择器相同(去#.)
									delimiter : ',',//数据分隔符
									field : {//数据的键名
										idName : 'id',
										titleName : 'name',
										childName : 'children'
									}
								});
							});
						});
					}
				});
			});
			
			//刷新表单
			form.render();
			//提交表单
			form.on("submit(submit)", function(data) {
				console.log($("#form").serialize());
				loadAjax( url, method, $("#form").serialize(), function(response) {
					baseCallBack(response, parentReloadCallBack);
				});
				return false;
			})

		});
	</script>
</body>
</html>